<?php
/**
 * Created by jinqiang on 2024/7/11 9:41.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Services\Wms;


use App\Http\Models\Mysql\SsyProcessingListDetailsDeliveryLogTable;
use App\Http\Models\Mysql\SsyProcessingWarehousingDataTable;

class ItemoutService
{
    public function search($param)
    {
        $conn = (new SsyProcessingListDetailsDeliveryLogTable())->whereNotNull('number');
        if($param['courier_number'] ?? ""){
            $conn = $conn->where('courier_number', 'like', $param['courier_number']."%");
        }
        if($param['number'] ?? ""){
            $conn = $conn->where('number', $param['number']);
        }
        if($param['createtime'] ?? []){
            $startTime = date('Y-m-d 00:00:00', strtotime($param['createtime'][0]));
            $endTime = date('Y-m-d 00:00:00', strtotime($param['createtime'][1]."+ 1 day"));
            $conn = $conn->whereBetween('createtime', [$startTime, $endTime]);
        }
        $res = $conn->orderBy('createtime', 'desc')->paginate((Int)$param['limit'])->toArray();
        return [
            'data' => $res['data'],
            'total' => $res['total']
        ];
    }

    public function searchFail($param)
    {
        $conn = (new SsyProcessingWarehousingDataTable())->where('code', '<>', 0);
        if($param['courier_number'] ?? ""){
            $conn = $conn->where('courier_number', 'like', $param['courier_number']."%");
        }
        if($param['msg'] ?? ""){
            $conn = $conn->where('datas', 'like', '%'.$param['msg'].'%');
        }
        if($param['createtime'] ?? []){
            $startTime = date('Y-m-d 00:00:00', strtotime($param['createtime'][0]));
            $endTime = date('Y-m-d 00:00:00', strtotime($param['createtime'][1]."+ 1 day"));
            $conn = $conn->whereBetween('createtime', [$startTime, $endTime]);
        }
        $res = $conn->orderBy('createtime', 'desc')->paginate((Int)$param['limit'])->toArray();
        return [
            'data' => $res['data'],
            'total' => $res['total']
        ];
    }
}
